package com.dangdang.service;

import java.util.Map;

import com.dangdang.domain.User;
import com.dangdang.util.Constants;

/**
 * 业务实现工厂类
 * 
 * @author Wangpeihu
 * @team [Never give up]
 * @since JDK1.6(建议)
 * @date 2010-1-28
 */
public class ServiceFactory {
	public static AuthorizeService getAuthorizeService() {
		return new AuthorizeServiceImpl();
	}

	public static CatalogService getCatalogService() {
		return new CatalogServiceImpl();
	}

	public static OrderService getOrderService() {
		return new OrderServiceImpl();
	}

	public static UserService getUserService() {
		return new UserServiceImpl();
	}

	/**
	 * 创建一个购物车管理业务实现类
	 * 
	 * @param session
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static CartService getCartService(Map session) {
		// 如果session里面没有,创建一个新的.并将其添加在session里面
		if (null == session.get(Constants.CART_SERVICE)) {
			CartService cartService = new CartServiceImpl((User) session
					.get(Constants.USER_KEY));
			session.put(Constants.CART_SERVICE, cartService);
			return cartService;
		} else {
			// 如果session里面有,就将其返回
			return (CartService) session.get(Constants.CART_SERVICE);
		}
	}

}
